import { EnvironmentParametersChannel } from "./SideChannels/EnvironmentParametersChannel";
import { SideChannelManager } from "./SideChannels/SideChannelManager";


/**
 * @en
 * A container for the Environment Parameters that may be modified during training.
 * The keys for those parameters are defined in the trainer configurations and the
 * the values are generated from the training process in features such as Curriculum Learning
 * and Environment Parameter Randomization.
 * One current assumption for all the environment parameters is that they are of type float.
 * 
 * @zh
 * 一个用于存储在训练过程中可能被修改的环境参数的容器。
 * 这些参数的键在训练器配置中定义，值是从训练过程中生成的，例如课程学习和环境参数随机化。
 * 目前所有环境参数的一个假设是它们都是浮点类型。
 * 
 */
export class EnvironmentParameters {
    private readonly _channel: EnvironmentParametersChannel;

    constructor() {
        this._channel = new EnvironmentParametersChannel();
        SideChannelManager.registerSideChannel(this._channel);
    }

    public getWithDefault(key: string, defaultValue: number): number {
        return this._channel.getWithDefault(key, defaultValue);
    }

    public registerCallback(key: string, action: (value: number) => void): void {
        this._channel.registerCallback(key, action);
    }

    public keys(): string[] {
        return this._channel.listParameters();
    }

    public dispose(): void {
        SideChannelManager.unregisterSideChannel(this._channel);
    }
}